package fallowme.comm;

import java.io.Serializable;

import fallowme.comm.ClientSideMessage;


/**
 * Messages sent from the server to clients. A message contains a type (enum), a payload (String), 
 * and a sender (String). 
 * 
 * @author Bruno Parra, Leo Dias, Miguel Lemos, Ruben Gomes
 * @version 1.0
 */
public class BirdSongClientSideMessage implements ClientSideMessage, Serializable {

	private Type type;
	private String payload;
	private String nickname;

	/**
	 * Creates a BirdSongClientSideMessage containing a type (enum), a payload (String), 
	 * and a sender (String). 
	 * 
	 * @param type The message type.
	 * @param payLoad The message payload.
	 * @param nickName The senders nickname.
	 */
	public BirdSongClientSideMessage(final Type type, final String payload, final String nickname){
		assert type != null;
		assert nickname != null && !nickname.isEmpty();
		//When a Birdsong message is being sent from one user to followers, the sender
		//is the nickname of the client
		if(type.equals(Type.BIRDSONG_MESSAGE))
			assert nickname != SERVER;

		this.type = type;
		this.payload = payload;
		this.nickname = nickname;
	}

	/**
	 * Gets the type of the message.
	 * 
	 * @return type of the message.
	 */
	@Override
	public Type getType() {
		return type;
	}

	/**
	 * Gets the payload of the message.
	 * 
	 * @return payload.
	 */
	@Override
	public String getPayload() {
		return payload;
	}

	/**
	 * Gets the sender of the message. 
	 * 
	 * @return nickname of the sender.
	 */
	@Override
	public String getSendersNickname() {
		return nickname;
	}
}
